
PACKAGE_VERSION = 1.0

prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
pixdir = ${libdir}/pix
includedir = @includedir@
mandir = @mandir@/man1
srcdir = ../@srcdir@
VPATH = ../@srcdir@

TCL_BIN = @TCL_BIN@
TCL_VERSION = @TCL_VERSION@

TK_VERSION = @TK_VERSION@
TCL_SH = @TCL_BIN@/tclsh@TCL_VERSION@

TCLTK_FLAGS = @TCLTKFLAGS@

TCL_LIBS = @TCLLIBS@
TK_LIBS = @TKLIBS@

PACKAGES = @TCL_PACKAGE_PATH@

top_builddir = ..

CC = @CC@
CDEFS = -DPACKAGE_VERSION=\"$(PACKAGE_VERSION)\" -DLIBDIR=\"$(libdir)\"
CFLAGS = -I../include -I$(srcdir)/include @CFLAGS@ @CWFLAG@ $(CDEFS) $(TCLTK_FLAGS)
# -DDEBUG
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
# -lefence


INSTALL = $(LIBTOOL) @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
YACC = @YACC@
RANLIB = @RANLIB@
RM = rm -f
STRIP = strip
SHELL = /bin/sh
CPLIB = @CPLIB@
EXT = @EXT@
SUBMAKE_COMM = @SUBMAKE_COMM@
SUBMAKE_COMM_CC = @SUBMAKE_COMM_CC@
LIBTOOL = @LIBTOOL@

CCLINK = $(LIBTOOL) --mode=link $(PURELINK) $(PURIFY) $(CC) $(LDFLAGS) $(CFLAGS)

OBJS = pdapilot.lo

LIB = pdapilot$(PACKAGE_VERSION).$(TCL_VERSION).la

TCLINTERP = pitclsh$(PACKAGE_VERSION).$(TCL_VERSION)
TKINTERP = piwish$(PACKAGE_VERSION).$(TK_VERSION)

WITHTCL = $(TCLINTERP)
WITHTK = $(TKINTERP)

INTERPS = $(@WITHTCL@) $(@WITHTK@)

PACKLIB = $(PACKAGES)/pdapilot$(PACKAGE_VERSION)

.SUFFIXES: .out .o .lo .cc .c .e .r .f .y .l .s .p

.c.lo:
	$(LIBTOOL) --mode=compile $(CC) $(CFLAGS) -c $<

all: $(LIB) $(INTERPS)

$(TCLINTERP): tclAppInit.o $(LIB)
	$(CCLINK) -o $(TCLINTERP) tclAppInit.o $(LIB) $(TCL_LIBS)

$(TKINTERP): tkAppInit.o $(LIB)
	$(CCLINK) -o $(TKINTERP) tkAppInit.o $(LIB) $(TK_LIBS)

installdirs:
	$(SHELL) ${srcdir}/scripts/mkinstalldirs $(PACKAGES) $(PACKLIB)

install: installdirs $(LIB)
	$(INSTALL_DATA) $(LIB) $(PACKAGES)/$(LIB)
	echo 'package ifneeded Pdapilot $(PACKAGE_VERSION).$(TCL_VERSION) [list load "[file join [file dirname $$dir] pdapilot$(PACKAGE_VERSION).$(TCL_VERSION).so]" Pdapilot]' >> $(PACKLIB)/pkgIndex.tcl 
	$(INSTALL_PROGRAM) $(TCLINTERP) $(TCL_BIN)/$(TCLINTERP)
	$(INSTALL_PROGRAM) $(TKINTERP) $(TCL_BIN)/$(TKINTERP)
	$(LIBTOOL) -n --finish $(PACKAGES)

uninstall: 
	-$(LIBTOOL) $(RM) $(PACKAGES)/$(LIB)
	grep -v '$(PACKAGE_VERSION).$(TCL_VERSION)' < $(PACKLIB)/pkgIndex.tcl > /tmp/plpkgIdx; cat /tmp/plpkgIdx > $(PACKLIB)/pkgIndex.tcl ; rm /tmp/plpkgIdx
	$(LIBTOOL) $(RM) $(TCL_BIN)/$(TCLINTERP)
	$(LIBTOOL) $(RM) $(TCL_BIN)/$(TKINTERP)
	$(LIBTOOL) -n --finish $(PACKAGES)

$(LIB): $(OBJS) Makefile
	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) \
		-export-dynamic -rpath $(PACKAGES) \
		-o $(LIB) $(OBJS) -L$(libdir) -lpisock

test: $(TCLINTERP) $(LIB)
	$(TCLINTERP) test.tcl

clean:
	$(RM) *.o *.a *.lo *.la core a.out *.so pitclsh* piwish*
	$(RM) -r .libs
	$(RM) *~
